<?php
/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 2017/8/18
 * Time: 17:34
 */

namespace app\admin\controller;

use think\Controller;
use think\Request;

class Content extends Controller
{
    protected $content;

    /**
     * Content constructor.
     */
    public function __construct()
    {
        parent::__construct();
        $this->content = new \app\admin\model\Content();
    }

    public function index()
    {

    }

    public function add()
    {
        if (Request::instance()->has("title", "post")) {
            $this->content->title = input("post.title");
            $this->content->keyword = input("post.keyword");
            $this->content->introduce = input("post.introduce");
            $this->content->content = input("post.content");
            $this->content->edit_time = date("Y-m-d H:i:s");
            $this->content->category = input("get.category");
            $this->content->poster = input("post.poster");
            $this->content->__token__ = input("post.__token__");
            $validate = new \app\admin\validate\Content();
            $result = $validate->check($this->content);
            if ($result) {//验证通过
                unset($this->content->__token__);
                $result = $this->content->save();
                if ($result) {
                    return $this->success("添加成功");
                } else {
                    return $this->error("添加失败");
                }
            } else {
                return $this->error($validate->getError());
            }
        } else {
            return $this->view->fetch("add");
        }
    }

    public function remove()
    {
    }

    public function edit()
    {
    }
}